﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EggCreater : MonoBehaviour
{
    public GameObject prefab;

    private void Start()
    {
        InvokeRepeating("CreatOne", 0, 2);
    }

    private void CreatOne()
    {
        //求得x轴的范围
        Vector3 leftBottom = Camera.main.ScreenToWorldPoint(Vector3.zero);
        Vector3 righTop = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height));

        //随机位置
        Vector3 pos = Vector3.zero;
        pos.x = Random.Range(leftBottom.x, righTop.x);
        pos.y = righTop.y + 2;
        //生成
        Instantiate(prefab, pos, Quaternion.identity);
    }
}